#!/bin/bash

if (( $EUID != 0 )); then
  echo "Eseguire lo script come amministratore"
  exit
fi

# installo dipendenze
apt install --yes build-essential lzip libgmp-dev libdb-dev

# installo unixodbc
apt install --yes iodbc unixodbc unixodbc-dev

# installo drivers
apt install --yes odbc-mariadb odbc-postgresql

# scarico gnucobol
wget https://sourceforge.net/projects/gnucobol/files/gnucobol/3.2/gnucobol-3.2.tar.lz

# decomprimo
tar --lzip -xvf gnucobol-3.2.tar.lz

# configuro, genero, installo
cd gnucobol-3.2
./configure
make
make install
ldconfig

cd ..

# scarico esqlOC
wget https://sourceforge.net/projects/gnucobol/files/contrib/esql/gnucobol-sql-3.0.tar.gz
tar xvfz gnucobol-sql-3.0.tar.gz

# configuro, genero, installo
cd gnucobol-sql-3.0
./configure
make
make install
ldconfig

cd ..

# aggiungo variabili di ambiente
echo 'export COB_LIBRARY_PATH=/usr/local/lib' >> /etc/profile
echo 'export COB_PRE_LOAD=libocsql' >> /etc/profile
